using ConsoleApi.Extensions;
using ConsoleApi.Services;
using ConsoleApi.Services.Interfaces;
using ConsoleApi.Models;
using ModelContextProtocol.AspNetCore;
using Microsoft.Extensions.Options;

var builder = WebApplication.CreateBuilder(args).Inject();

// 注册MCP服务并扫描程序集工具
builder.Services
    .AddMcpServer()
    .WithHttpTransport() // 添加HTTP传输支持
    .WithToolsFromAssembly(typeof(Program).Assembly);

// 注册HttpClient
builder.Services.AddHttpClient();

// 注册OpenWeatherMap配置
builder.Services.Configure<OpenWeatherMapConfig>(
    builder.Configuration.GetSection("OpenWeatherMap"));

// 注册测试服务
builder.Services.AddScoped<TestMcpService>();

// 注册真实天气服务
builder.Services.AddScoped<IRealWeatherService, RealWeatherService>();

// 注册天气预警规则引擎
builder.Services.AddScoped<IWeatherAlertRuleEngine, WeatherAlertRuleEngine>();

// 注册生产数据服务
builder.Services.AddScoped<IProductionDataService, ProductionDataService>();

// 注册增强MCP工具服务
builder.Services.AddScoped<EnhancedMcpToolService>();

var app = builder.Build();

//跨域
app.UseCors(x=>x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthentication();

app.UseAuthorization();

app.MapControllers();

// 注册MCP端点
app.MapMcp();

app.Run();
